﻿using System;
using System.Linq;
using System.Linq.Expressions;
using NC.Infrastructure.Data;
using NC.Infrastructure.DomainDto.Identity;
using NC.Infrastructure.Mapper;
using NC.Service.Person;
using domainEntity = NC.Infrastructure.Domain.News.Apply;

namespace NC.Service.Apply
{
    public class ApplyService: IApplyService
    {
        private readonly IRepository<domainEntity> _applyRepository;

        public ApplyService(IRepository<domainEntity> applyRepository)    
        {
            this._applyRepository = applyRepository;
        }

        public domainEntity Get(int id)
        {
            return _applyRepository.Get(id);
        }

        public IQueryable<domainEntity> GetAll()
        {
            return _applyRepository.Entities;
        }

        public IQueryable<domainEntity> Get(Expression<Func<domainEntity, bool>> filter)
        {
            return _applyRepository.Get(filter);
        }

        public void Insert(domainEntity entity)
        {
            _applyRepository.Insert(entity);
        }

        public void Update(domainEntity entity)
        {
            _applyRepository.Update(entity);
        }

        public void Delete(domainEntity entity)
        {
            _applyRepository.Delete(entity);
        }

        public void Commit()
        {
            _applyRepository.Commit();
        }

        public IQueryable<ApplyPersonDto> GetApplyPersons()
        {
            return GetApplyPersons(n => n.Id != 0);
        }

        public IQueryable<ApplyPersonDto> GetApplyPersons(
            Expression<Func<Infrastructure.Domain.News.Apply, bool>> filterExpression)
        {
            return _applyRepository.Entities.Where(filterExpression).MapToApplyPerson();
        }

    }
}
